"use strict";

import $P from './public';

// 获取当前系统时间戳
function GetTS() {
  return parseInt(new Date().getTime() / 1000);
}

// 时间对象转时间戳
function Date2TS(date) {
  if ($P.Invalid(date)) return "";

  if (typeof date === "string") date = new Date(date);

  return date.getTime ? parseInt(date.getTime() / 1000) : '';
}

// 时间戳转时间对象
function TS2Date(ts) {
  if ($P.Invalid(ts)) {
    return new Date();
  }
  let c = 1000;
  if ((ts + "").length > 10) {
    c = 1;
  }
  let d = new Date();
  d.setTime(parseInt(ts) * c);
  return d;
}

// GMT时间转普通格式时间
function GMTToStr(time) {
  let date = new Date(time);
  let Str =
    date.getFullYear() +
    "-" +
    (date.getMonth() + 1) +
    "-" +
    date.getDate() +
    " " +
    date.getHours() +
    ":" +
    date.getMinutes() +
    ":" +
    date.getSeconds();
  return Str;
}
// 普通格式时间转GMT时间
function StrToGMT(time){
  let GMT = new Date(time)
  return GMT
}

export default {
  GetTS,
  Date2TS,
  TS2Date,
  GMTToStr,
  StrToGMT,
};
